#namespace("com.htwy.core.model.Orgnazation")
  #sql("findByCondition")
    SELECT uuid, name, fullName, rank, sign, route, serial, parentId, creator, createTime, mender, modifyTime, deletedBy, deletedMarker, deleteTime, childrenCount
    FROM ht_sys_orgnazation
    #WHERE()
      #if(uuid)
        uuid = #para(uuid)
      #end
      #if(name)
        AND name = #para(name)
      #end
      #if(fullName)
        AND fullName = #para(fullName)
      #end
      #if(rank)
        AND rank = #para(rank)
      #end
      #if(sign)
        AND sign = #para(sign)
      #end
      #if(route)
        AND route = #para(route)
      #end
      #if(serial)
        AND serial = #para(serial)
      #end
      #if(parentId)
        AND parentId = #para(parentId)
      #end
      #if(creator)
        AND creator = #para(creator)
      #end
      #if(createTime)
        AND createTime = #para(createTime)
      #end
      #if(mender)
        AND mender = #para(mender)
      #end
      #if(modifyTime)
        AND modifyTime = #para(modifyTime)
      #end
      #if(deletedBy)
        AND deletedBy = #para(deletedBy)
      #end
      #if(deletedMarker)
        AND deletedMarker = #para(deletedMarker)
      #end
      #if(deleteTime)
        AND deleteTime = #para(deleteTime)
      #end
      #if(childrenCount)
        AND childrenCount = #para(childrenCount)
      #end
    #end
    ORDER BY serial asc
    
  #end

  #sql("deleteByPks")
    DELETE FROM ht_sys_orgnazation
    #WHERE()
      #if(pks != null && pks.length > 0)
        #if(pks.length>1)
          uuid in (
          #for(tempId : pks)
            #if(for.first)
              #para(tempId)
            #else
              , #para(tempId)
            #end
          #end
          )
        #else
          uuid = #para(pks[0])
        #end
      #end
    #end
  #end

  #sql("updateChildrenCount")
    UPDATE ht_sys_orgnazation p
    SET p.childrenCount = (SELECT R.CNT FROM
    (SELECT COUNT(c.uuid) CNT FROM ht_sys_orgnazation c WHERE c.parentId = #para(uuid)) R)
    WHERE p.uuid = #para(uuid)
  #end

  #sql("getMaxSerialByParentId")
    SELECT MAX(serial) FROM ht_sys_orgnazation WHERE parentId = #para(parentId)
  #end

#end